/**
 * Created by zhanglihe on 16/1/15.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'datepicker',
    'highCharts'
], function ($, common, ready, Collection, datepicker, highCharts) {

    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'partner/goods_cate_count',
                condition: {},
                callback: function () {
                    loaded();//移除加载效果
                    var series = _this.collection.result.data.series;
                    var tab = _this.collection.result.data.tab;

                    if (_this.collection.result.count < 1) {
                        $('#data-highcharts').html('<center>无数据</center>');
                    } else {
                        $('#data-highcharts').highcharts({
                            chart: {
                                type: 'column'
                            },
                            title: {
                                text: '类目统计'
                            },
                            subtitle: {
                                text: ''
                            },
                            xAxis: {
                                categories: tab
                            },
                            yAxis: {
                                min: 0,
                                title: {
                                    text: '参考值'
                                }
                            },
                            tooltip: {
                                headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                                pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y}</b></td></tr>',
                                footerFormat: '</table>',
                                shared: true,
                                useHTML: true
                            },
                            plotOptions: {
                                column: {
                                    pointPadding: 0.2,
                                    borderWidth: 0
                                }
                            },
                            series: series
                        });
                    }
                }
            });
            this.collection.fetch();
        },

        event: function () {
            var _this = this;
            $('#btn-date-type').find('a').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.date_type = $(this).attr('rel');
                $(this).addClass('active').siblings().removeClass('active');
                _this.collection.reload();
            });
        }
    };
    new index();

});